/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.enterprise.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.enterprise.controller.CompanyBasicInfController;
import org.springblade.modules.enterprise.entity.CompanyBasicInf;
import org.springblade.modules.enterprise.service.ICompanyBasicInfService;
import org.springblade.modules.enterprise.vo.CompanyBasicInfVO;
import org.springblade.modules.enterprise.wrapper.CompanyBasicInfWrapper;
import org.springblade.modules.system.service.IDictService;
import org.springblade.modules.system.vo.DictVO;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * 控制器
 *
 * @author BladeX
 * @since 2021-07-28
 */
@RestController
@AllArgsConstructor
@RequestMapping("enterprise/company-info")
@Api(value = "企业信息", tags = "(api)企业信息")
public class CompanyInfApi extends BladeController {

	private final CompanyBasicInfController companyBasicInfController;

	private final ICompanyBasicInfService companyBasicInfService;

	private final IDictService dictService;

	/**
	 * 企业政策查阅+1
	 */
	@PostMapping("/look-policy-incr")
	@ApiOperation(value = "政策查阅+1")
	public R lookPolicyIncr(@ApiParam("企业政务账户") @RequestParam String userName) {
		return R.data(companyBasicInfService.lookPolicyIncr(userName));
	}

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "获取企业信息", notes = "传入companyBasicInf")
	public R<CompanyBasicInfVO> detail(CompanyBasicInf companyBasicInf) {
		CompanyBasicInf detail = companyBasicInfService.getOne(Condition.getQueryWrapper(companyBasicInf));
		return R.data(CompanyBasicInfWrapper.build().entityVO(detail));
	}

	/**
	 * 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入companyBasicInf")
	public R<IPage<CompanyBasicInfVO>> list(CompanyBasicInf companyBasicInf, Query query) {
		IPage<CompanyBasicInf> pages = companyBasicInfService.page(Condition.getPage(query), Condition.getQueryWrapper(companyBasicInf));
		return R.data(CompanyBasicInfWrapper.build().pageVO(pages));
	}

	/**
	 * 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入companyBasicInf")
	public R<IPage<CompanyBasicInfVO>> page(CompanyBasicInfVO companyBasicInf, Query query) {
		IPage<CompanyBasicInfVO> pages = companyBasicInfService.selectCompanyBasicInfPage(Condition.getPage(query), companyBasicInf);
		return R.data(pages);
	}

	/**
	 * 此数据根据配置的字典查询
	 * 获取所属行业分类
	 * ! 如没有id：1423902186016276481L code：industry_type  系统会报错
	 *
	 * @return
	 */
	@GetMapping("/industry-type")
	@ApiOperationSupport(order = 0)
	@ApiOperation(value = "行业分类信息", notes = "industry type")
	public R<List<DictVO>> industryType() {
		HashMap<String, Object> map = new HashMap<>();
		map.put("code", "industry_type");
		return R.data(dictService.childList(map, 1423902186016276481L));
	}
}
